home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP07.ZIP / CHAP07 / SCHMOO / DOCUMENT.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  20KB  |  970 lines

  1. /*
  2.  * DOCUMENT.CPP
  3.  *
  4.  * Implementation of the CSchmooDoc derivation of CDocument as
  5.  * well as an implementation of CPolylineAdviseSink.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include "schmoo.h"
  18.  
  19.  
  20.  
  21. /*
  22.  * CSchmooDoc::CSchmooDoc
  23.  * CSchmooDoc::~CSchmooDoc
  24.  *
  25.  * Constructor Parameters:
  26.  *  hInst           HINSTANCE of the application.
  27.  */
  28.  
  29. CSchmooDoc::CSchmooDoc(HINSTANCE hInst)
  30.     : CDocument(hInst)
  31.     {
  32.     m_pPL=NULL;
  33.     m_pPLAdv=NULL;
  34.     m_uPrevSize=SIZE_RESTORED;
  35.     return;
  36.     }
  37.  
  38.  
  39. CSchmooDoc::~CSchmooDoc(void)
  40.     {
  41.     //Clean up the allocations we did in FInit
  42.     if (NULL!=m_pPL)
  43.         delete m_pPL;
  44.  
  45.     if (NULL!=m_pPLAdv)
  46.         delete m_pPLAdv;
  47.  
  48.     return;
  49.     }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. /*
  57.  * CSchmooDoc::FInit
  58.  *
  59.  * Purpose:
  60.  *  Initializes an already created document window.  The client actually
  61.  *  creates the window for us, then passes that here for further
  62.  *  initialization.
  63.  *
  64.  * Parameters:
  65.  *  pDI             LPDOCUMENTINIT containing initialization parameters.
  66.  *
  67.  * Return Value:
  68.  *  BOOL            TRUE if the function succeeded, FALSE otherwise.
  69.  */
  70.  
  71. BOOL CSchmooDoc::FInit(LPDOCUMENTINIT pDI)
  72.     {
  73.     RECT        rc;
  74.  
  75.     //Change the stringtable range to our customization.
  76.     pDI->idsMin=IDS_DOCUMENTMIN;
  77.     pDI->idsMax=IDS_DOCUMENTMAX;
  78.  
  79.     //Do default initialization
  80.     if (!CDocument::FInit(pDI))
  81.         return FALSE;
  82.  
  83.     //Add the Polyline stuff we need.
  84.     m_pPLAdv=new CPolylineAdviseSink((LPVOID)this);
  85.     m_pPL   =new CPolyline(m_hInst);
  86.  
  87.     //Attempt to create our contained Polyline.
  88.     GetClientRect(m_hWnd, &rc);
  89.     InflateRect(&rc, -8, -8);
  90.  
  91.     if (!m_pPL->FInit(m_hWnd, &rc, WS_CHILD | WS_VISIBLE
  92.         , ID_POLYLINE, m_pPLAdv))
  93.         return FALSE;
  94.  
  95.     return TRUE;
  96.     }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /*
  105.  * CSchmooDoc::FMessageHook
  106.  *
  107.  * Purpose:
  108.  *  Processes WM_SIZE for the document so we can resize the Polyline.
  109.  *
  110.  * Parameters:
  111.  *  <WndProc Parameters>
  112.  *  pLRes           LRESULT FAR * in which to store the return value
  113.  *                  for the message.
  114.  *
  115.  * Return Value:
  116.  *  BOOL            TRUE to prevent further processing, FALSE otherwise.
  117.  */
  118.  
  119. BOOL CSchmooDoc::FMessageHook(HWND hWnd, UINT iMsg, WPARAM wParam
  120.     , LPARAM lParam, LRESULT FAR *pLRes)
  121.     {
  122.     UINT        dx, dy;
  123.     RECT        rc;
  124.  
  125.     if (WM_SIZE==iMsg)
  126.         {
  127.         //Don't effect the Polyline size to or from minimized state.
  128.         if (SIZE_MINIMIZED!=wParam && SIZE_MINIMIZED !=m_uPrevSize)
  129.             {
  130.             //When we change size, resize any Polyline we hold.
  131.             dx=LOWORD(lParam);
  132.             dy=HIWORD(lParam);
  133.  
  134.             /*
  135.              * If we are getting WM_SIZE in response to a Polyline
  136.              * notification, then don't resize the Polyline window again.
  137.              */
  138.             if (!m_fNoSize && NULL!=m_pPL)
  139.                 {
  140.                 //Resize the polyline to fit the new client
  141.                 SetRect(&rc, 8, 8, dx-8, dy-8);
  142.                 m_pPL->RectSet(&rc, FALSE);
  143.  
  144.                 /*
  145.                  * We consider sizing something that makes the file dirty,
  146.                  * but not until we've finished the create process, which
  147.                  * is why we set fNoDirty to FALSE in WM_CREATE since we
  148.                  * get a WM_SIZE on the first creation.
  149.                  */
  150.                 if (!m_fNoDirty)
  151.                     FDirtySet(TRUE);
  152.  
  153.                 SetRect(&rc, 0, 0, dx, dy);
  154.  
  155.                 if (NULL!=m_pAdv)
  156.                     m_pAdv->OnSizeChange((LPCDocument)this, &rc);
  157.  
  158.                 m_fNoDirty=FALSE;
  159.                 }
  160.             }
  161.  
  162.         m_uPrevSize=wParam;
  163.         }
  164.  
  165.     /*
  166.      * We return FALSE even on WM_SIZE so we can let the default procedure
  167.      * handle maximized MDI child windows appropriately.
  168.      */
  169.     return FALSE;
  170.     }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. /*
  180.  * CSchmooDoc::Clear
  181.  *
  182.  * Purpose:
  183.  *  Sets all contents in the document back to defaults with no filename.
  184.  *
  185.  * Paramters:
  186.  *  None
  187.  *
  188.  * Return Value:
  189.  *  None
  190.  */
  191.  
  192. void CSchmooDoc::Clear(void)
  193.     {
  194.     //Completely reset the polyline
  195.     m_pPL->New();
  196.  
  197.     CDocument::Clear();
  198.     m_lVer=0;
  199.     return;
  200.     }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. /*
  208.  * CSchmooDoc::ULoad
  209.  *
  210.  * Purpose:
  211.  *  Loads a given document without any user interface overwriting the
  212.  *  previous contents of the Polyline window.  We do this by opening
  213.  *  the file and telling the Polyline to load itself from that file.
  214.  *
  215.  * Parameters:
  216.  *  fChangeFile     BOOL indicating if we're to update the window title
  217.  *                  and the filename from using this file.
  218.  *  pszFile         LPSTR to the filename to load, NULL if the file is
  219.  *                  new and untitled.
  220.  *
  221.  * Return Value:
  222.  *  UINT            An error value from DOCERR_*
  223.  */
  224.  
  225. UINT CSchmooDoc::ULoad(BOOL fChangeFile, LPSTR pszFile)
  226.     {
  227.     HRESULT         hr;
  228.     LPSTORAGE       pIStorage;
  229.  
  230.     if (NULL==pszFile)
  231.         {
  232.         //For a new untitled document, just rename ourselved.
  233.         Rename(NULL);
  234.         m_lVer=VERSIONCURRENT;
  235.         return DOCERR_NONE;
  236.         }
  237.  
  238.     /*
  239.      * If this is not a Compound File, open the file using STGM_CONVERT
  240.      * in TRANSACTED mode to effectively see old files as a storage with
  241.      * one stream called "CONTENTS" (which is conveniently the name we use
  242.      * in the new files).  We must use STGM_TRANSACTED here or else
  243.      * the old file will be immediately converted on disk:  we only want
  244.      * a converted image in memory from which to read.  In addition,
  245.      * note that we need STGM_READWRITE as well since conversion is
  246.      * inherently a write operation.
  247.      */
  248.  
  249.     pIStorage=NULL;
  250.  
  251.     if (NOERROR!=StgIsStorageFile(pszFile))
  252.         {
  253.         hr=StgCreateDocfile(pszFile, STGM_TRANSACTED | STGM_READWRITE
  254.             | STGM_CONVERT | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  255.  
  256.         if (FAILED(hr))
  257.             {
  258.             //If we were denied write access, try to load the old way
  259.             if (STG_E_ACCESSDENIED==GetScode(hr))
  260.                 m_lVer=m_pPL->ReadFromFile(pszFile);
  261.             else
  262.                 return DOCERR_COULDNOTOPEN;
  263.             }
  264.         }
  265.     else
  266.         {
  267.         hr=StgOpenStorage(pszFile, NULL, STGM_DIRECT | STGM_READ
  268.             | STGM_SHARE_EXCLUSIVE, NULL, 0, &pIStorage);
  269.  
  270.         if (FAILED(hr))
  271.             return DOCERR_COULDNOTOPEN;
  272.         }
  273.  
  274.     if (NULL!=pIStorage)
  275.         {
  276.         m_lVer=m_pPL->ReadFromStorage(pIStorage);
  277.         pIStorage->Release();
  278.         }
  279.  
  280.     if (POLYLINE_E_READFAILURE==m_lVer)
  281.         return DOCERR_READFAILURE;
  282.  
  283.     if (POLYLINE_E_UNSUPPORTEDVERSION==m_lVer)
  284.         return DOCERR_UNSUPPORTEDVERSION;
  285.  
  286.     if (fChangeFile)
  287.         Rename(pszFile);
  288.  
  289.     //Importing a file makes things dirty
  290.     FDirtySet(!fChangeFile);
  291.  
  292.     return DOCERR_NONE;
  293.     }
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. /*
  302.  * CSchmooDoc::USave
  303.  *
  304.  * Purpose:
  305.  *  Writes the file to a known filename, requiring that the user has
  306.  *  previously used FileOpen or FileSaveAs in order to have a filename.
  307.  *
  308.  * Parameters:
  309.  *  uType           UINT indicating the type of file the user requested
  310.  *                  to save in the File Save As dialog.
  311.  *  pszFile         LPSTR under which to save.  If NULL, use the current name.
  312.  *
  313.  * Return Value:
  314.  *  UINT            An error value from DOCERR_*
  315.  */
  316.  
  317. UINT CSchmooDoc::USave(UINT uType, LPSTR pszFile)
  318.     {
  319.     LONG        lVer, lRet;
  320.     UINT        uTemp;
  321.     BOOL        fRename=TRUE;
  322.     HRESULT     hr;
  323.     LPSTORAGE   pIStorage;
  324.  
  325.     if (NULL==pszFile)
  326.         {
  327.         fRename=FALSE;
  328.         pszFile=m_szFile;
  329.         }
  330.  
  331.     /*
  332.      * Type 1 is the current version, type 2 is version 1.0 of the Polyline
  333.      * so we use this to send the right version to CPolyline::WriteToFile.
  334.      */
  335.  
  336.     switch (uType)
  337.         {
  338.         case 0:         //From Save, use loaded version.
  339.             lVer=m_lVer;
  340.             break;
  341.  
  342.         case 1:
  343.             lVer=VERSIONCURRENT;
  344.             break;
  345.  
  346.         case 2:
  347.             lVer=MAKELONG(0, 1);    //1.0
  348.             break;
  349.  
  350.         default:
  351.             return DOCERR_UNSUPPORTEDVERSION;
  352.         }
  353.  
  354.     /*
  355.      * If the version the user wants to save is different than the
  356.      * version that we loaded, and m_lVer is not zero (new document),
  357.      * then inform the user of the version change and verify.
  358.      */
  359.     if (0!=m_lVer && m_lVer!=lVer)
  360.         {
  361.         char        szMsg[128];
  362.  
  363.         wsprintf(szMsg, PSZ(IDS_VERSIONCHANGE), (UINT)HIWORD(m_lVer)
  364.             , (UINT)LOWORD(m_lVer), (UINT)HIWORD(lVer), (UINT)LOWORD(lVer));
  365.  
  366.         uTemp=MessageBox(m_hWnd, szMsg, PSZ(IDS_DOCUMENTCAPTION), MB_YESNOCANCEL);
  367.  
  368.         if (IDCANCEL==uTemp)
  369.             return DOCERR_CANCELLED;
  370.  
  371.         //If the user won't upgrade versions, revert to loaded version.
  372.         if (IDNO==uTemp)
  373.             lVer=m_lVer;
  374.         }
  375.  
  376.     /*
  377.      * For 1.0 files, still use the old code.  For new files, use
  378.      * storages instead
  379.      */
  380.     if (lVer==MAKELONG(0, 1))
  381.         lRet=m_pPL->WriteToFile(pszFile, lVer);
  382.     else
  383.         {
  384.         hr=StgCreateDocfile(pszFile, STGM_DIRECT | STGM_READWRITE
  385.             | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  386.  
  387.         if (FAILED(hr))
  388.             return DOCERR_COULDNOTOPEN;
  389.  
  390.         //Mark this as one of our class
  391.         WriteClassStg(pIStorage, CLSID_Schmoo2Figure);
  392.  
  393.         //Write user-readable class information
  394.         WriteFmtUserTypeStg(pIStorage, m_cf, PSZ(IDS_CLIPBOARDFORMAT));
  395.  
  396.         lRet=m_pPL->WriteToStorage(pIStorage, lVer);
  397.         pIStorage->Release();
  398.         }
  399.  
  400.     if (POLYLINE_E_NONE!=lRet)
  401.         return DOCERR_WRITEFAILURE;
  402.  
  403.     //Saving makes us clean
  404.     FDirtySet(FALSE);
  405.  
  406.     //Update the known version of this document.
  407.     m_lVer=lVer;
  408.  
  409.     if (fRename)
  410.         Rename(pszFile);
  411.  
  412.     return DOCERR_NONE;
  413.     }
  414.  
  415.  
  416.  
  417.  
  418.  
  419. /*
  420.  * CSchmooDoc::Undo
  421.  *
  422.  * Purpose:
  423.  *  Reverses a previous action.
  424.  *
  425.  * Parameters:
  426.  *  None
  427.  *
  428.  * Return Value:
  429.  *  None
  430.  */
  431.  
  432. void CSchmooDoc::Undo(void)
  433.     {
  434.     m_pPL->Undo();
  435.     return;
  436.     }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444. /*
  445.  * CSchmooDoc::FClip
  446.  *
  447.  * Purpose:
  448.  *  Places a private format, a metafile, and a bitmap of the display
  449.  *  on the clipboard, optionally implementing Cut by deleting the
  450.  *  data in the current window after rendering.
  451.  *
  452.  * Parameters:
  453.  *  hWndFrame       HWND of the main window
  454.  *  fCut            BOOL indicating cut (TRUE) or copy (FALSE).
  455.  *
  456.  * Return Value:
  457.  *  BOOL            TRUE if successful, FALSE otherwise.
  458.  */
  459.  
  460. BOOL CSchmooDoc::FClip(HWND hWndFrame, BOOL fCut)
  461.     {
  462.     BOOL            fRet=TRUE;
  463.     HGLOBAL         hMem;
  464.     UINT            i;
  465.     static UINT     rgcf[3]={0, CF_METAFILEPICT, CF_BITMAP};
  466.     const UINT      cFormats=3;
  467.  
  468.     //CHAPTER7MOD
  469.     static DWORD    rgtm[3]={TYMED_HGLOBAL, TYMED_MFPICT, TYMED_GDI};
  470.     LPDATAOBJECT    pIDataObject;
  471.     HRESULT         hr;
  472.     STGMEDIUM       stm;
  473.     FORMATETC       fe;
  474.  
  475.     hr=CoCreateInstance(CLSID_DataTransferObject, NULL, CLSCTX_INPROC_SERVER
  476.         , IID_IDataObject, (LPVOID FAR *)&pIDataObject);
  477.  
  478.     if (FAILED(hr))
  479.         return NULL;
  480.     //End CHAPTER7MOD
  481.  
  482.     rgcf[0]=m_cf;
  483.  
  484.     for (i=0; i < cFormats; i++)
  485.         {
  486.         //Copy private data first.
  487.         hMem=RenderFormat(rgcf[i]);
  488.  
  489.         if (NULL!=hMem)
  490.             {
  491.             //CHAPTER7MOD
  492.             stm.hGlobal=hMem;
  493.             stm.tymed=rgtm[i];
  494.             stm.pUnkForRelease=NULL;
  495.  
  496.             SETDefFormatEtc(fe, rgcf[i], rgtm[i]);
  497.  
  498.             pIDataObject->SetData(&fe, &stm, TRUE);
  499.             //End CHAPTER7MOD
  500.             }
  501.         }
  502.  
  503.     //CHAPTER7MOD
  504.     fRet=SUCCEEDED(OleSetClipboard(pIDataObject));
  505.     pIDataObject->Release();
  506.     //End CHAPTER7MOD
  507.  
  508.     //Delete our current data if copying succeeded.
  509.     if (fRet && fCut)
  510.         {
  511.         m_pPL->New();
  512.         FDirtySet(TRUE);
  513.         }
  514.  
  515.     return fRet;
  516.     }
  517.  
  518.  
  519.  
  520.  
  521. /*
  522.  * CSchmooDoc::RenderFormat
  523.  *
  524.  * Purpose:
  525.  *  Renders a specific clipboard format into global memory.
  526.  *
  527.  * Parameters:
  528.  *  cf              UINT format to render.
  529.  *
  530.  * Return Value:
  531.  *  HGLOBAL         Global memory handle containing the data.
  532.  */
  533.  
  534. HGLOBAL CSchmooDoc::RenderFormat(UINT cf)
  535.     {
  536.     HGLOBAL     hMem;
  537.  
  538.     if (cf==m_cf)
  539.         {
  540.         m_pPL->DataGetMem(VERSIONCURRENT, &hMem);
  541.         return hMem;
  542.         }
  543.  
  544.     switch (cf)
  545.         {
  546.         case CF_METAFILEPICT:
  547.             return m_pPL->RenderMetafilePict();
  548.  
  549.         case CF_BITMAP:
  550.             return (HGLOBAL)m_pPL->RenderBitmap();
  551.         }
  552.  
  553.     return NULL;
  554.     }
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563. /*
  564.  * CSchmooDoc::FQueryPaste
  565.  *
  566.  * Purpose:
  567.  *  Determines if we can paste data from the clipboard.
  568.  *
  569.  * Parameters:
  570.  *  None
  571.  *
  572.  * Return Value:
  573.  *  BOOL            TRUE if data is available, FALSE otherwise.
  574.  */
  575.  
  576. BOOL CSchmooDoc::FQueryPaste(void)
  577.     {
  578.     //CHAPTER7MOD
  579.     LPDATAOBJECT    pIDataObject;
  580.     BOOL            fRet;
  581.  
  582.     if (FAILED(OleGetClipboard(&pIDataObject)))
  583.         return FALSE;
  584.  
  585.     fRet=FQueryPasteFromData(pIDataObject);
  586.     pIDataObject->Release();
  587.     return fRet;
  588.     //End CHAPTER7MOD
  589.     }
  590.  
  591.  
  592.  
  593. //CHAPTER7MOD
  594. /*
  595.  * CSchmooDoc::FQueryPasteFromData
  596.  * (Protected)
  597.  *
  598.  * Purpose:
  599.  *  Determines if we can paste data from a data object.
  600.  *
  601.  * Parameters:
  602.  *  pIDataObject    LPDATAOBJECT from which we might want to paste.
  603.  *
  604.  * Return Value:
  605.  *  BOOL            TRUE if data is available, FALSE otherwise.
  606.  */
  607.  
  608. BOOL CSchmooDoc::FQueryPasteFromData(LPDATAOBJECT pIDataObject)
  609.     {
  610.     FORMATETC       fe;
  611.  
  612.     SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
  613.     return (NOERROR==pIDataObject->QueryGetData(&fe));
  614.     }
  615. //End CHAPTER7MOD
  616.  
  617.  
  618.  
  619.  
  620. /*
  621.  * CSchmooDoc::FPaste
  622.  *
  623.  * Purpose:
  624.  *  Retrieves the private data format from the clipboard and sets it
  625.  *  to the current figure in the editor window.
  626.  *
  627.  *  Note that if this function is called, then the clipboard format
  628.  *  is available because the Paste menu item is only enabled if the
  629.  *  format is present.
  630.  *
  631.  * Parameters:
  632.  *  hWndFrame       HWND of the main window
  633.  *
  634.  * Return Value:
  635.  *  BOOL            TRUE if successful, FALSE otherwise.
  636.  */
  637.  
  638. BOOL CSchmooDoc::FPaste(HWND hWndFrame)
  639.     {
  640.     //CHAPTER7MOD
  641.     LPDATAOBJECT    pIDataObject;
  642.     BOOL            fRet;
  643.  
  644.     if (FAILED(OleGetClipboard(&pIDataObject)))
  645.         return FALSE;
  646.  
  647.     fRet=FPasteFromData(pIDataObject);
  648.     pIDataObject->Release();
  649.  
  650.     //End CHAPTER7MOD
  651.     return fRet;
  652.     }
  653.  
  654.  
  655.  
  656. //CHAPTER7MOD
  657. /*
  658.  * CSchmooDoc::FPasteFromData
  659.  * (Protected)
  660.  *
  661.  * Purpose:
  662.  *  Retrieves the private data format from a data object and sets it
  663.  *  to the current figure in the editor window.
  664.  *
  665.  * Parameters:
  666.  *  pIDataObject    LPDATAOBJECT from which to paste.
  667.  *
  668.  * Return Value:
  669.  *  BOOL            TRUE if successful, FALSE otherwise.
  670.  */
  671.  
  672. BOOL CSchmooDoc::FPasteFromData(LPDATAOBJECT pIDataObject)
  673.     {
  674.     FORMATETC       fe;
  675.     STGMEDIUM       stm;
  676.     BOOL            fRet;
  677.  
  678.     SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
  679.     fRet=SUCCEEDED(pIDataObject->GetData(&fe, &stm));
  680.  
  681.     if (fRet && NULL!=stm.hGlobal)
  682.         {
  683.         m_pPL->DataSetMem(stm.hGlobal, FALSE, FALSE, TRUE);
  684.         ReleaseStgMedium(&stm);
  685.         FDirtySet(TRUE);
  686.         }
  687.  
  688.     return fRet;
  689.     }
  690. //End CHAPTER7MOD
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698. /*
  699.  * CSchmooDoc::ColorSet
  700.  *
  701.  * Purpose:
  702.  *  Changes a color used in our contained Polyline.
  703.  *
  704.  * Parameters:
  705.  *  iColor          UINT index of the color to change.
  706.  *  cr              COLORREF new color.
  707.  *
  708.  * Return Value:
  709.  *  COLORREF        Previous color for the given index.
  710.  */
  711.  
  712. COLORREF CSchmooDoc::ColorSet(UINT iColor, COLORREF cr)
  713.     {
  714.     return m_pPL->ColorSet(iColor, cr);
  715.     }
  716.  
  717.  
  718.  
  719.  
  720.  
  721. /*
  722.  * CSchmooDoc::ColorGet
  723.  *
  724.  * Purpose:
  725.  *  Retrieves a color currently in use in the Polyline.
  726.  *
  727.  * Parameters:
  728.  *  iColor          UINT index of the color to retrieve.
  729.  *
  730.  * Return Value:
  731.  *  COLORREF        Current color for the given index.
  732.  */
  733.  
  734. COLORREF CSchmooDoc::ColorGet(UINT iColor)
  735.     {
  736.     return m_pPL->ColorGet(iColor);
  737.     }
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744. /*
  745.  * CSchmooDoc::LineStyleSet
  746.  *
  747.  * Purpose:
  748.  *  Changes the line style currently used in the Polyline
  749.  *
  750.  * Parameters:
  751.  *  iStyle          UINT index of the new line style to use.
  752.  *
  753.  * Return Value:
  754.  *  UINT            Previous line style.
  755.  */
  756.  
  757.  
  758. UINT CSchmooDoc::LineStyleSet(UINT iStyle)
  759.     {
  760.     return m_pPL->LineStyleSet(iStyle);
  761.     }
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769. /*
  770.  * CSchmooDoc::LineStyleGet
  771.  *
  772.  * Purpose:
  773.  *  Retrieves the line style currently used in the Polyline
  774.  *
  775.  * Parameters:
  776.  *  None
  777.  *
  778.  * Return Value:
  779.  *  UINT            Current line style.
  780.  */
  781.  
  782.  
  783. UINT CSchmooDoc::LineStyleGet(void)
  784.     {
  785.     return m_pPL->LineStyleGet();
  786.     }
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795. /*
  796.  * CPolylineAdviseSink::CPolylineAdviseSink
  797.  * CPolylineAdviseSink::~CPolylineAdviseSink
  798.  *
  799.  * Constructor Parameters:
  800.  *  pv              LPVOID to store in this object
  801.  */
  802.  
  803. CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv)
  804.     {
  805.     m_pv=pv;
  806.     return;
  807.     }
  808.  
  809.  
  810. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  811.     {
  812.     return;
  813.     }
  814.  
  815.  
  816.  
  817.  
  818.  
  819. /*
  820.  * CPolylineAdviseSink::OnPointChange
  821.  *
  822.  * Purpose:
  823.  *  Informs the document that the polyline added or removed a point.
  824.  *
  825.  * Parameters:
  826.  *  None
  827.  *
  828.  * Return Value:
  829.  *  None
  830.  */
  831.  
  832. void CPolylineAdviseSink::OnPointChange(void)
  833.     {
  834.     LPCDocument pDoc=(LPCDocument)m_pv;
  835.  
  836.     pDoc->FDirtySet(TRUE);
  837.     return;
  838.     }
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845. /*
  846.  * CPolylineAdviseSink::OnSizeChange
  847.  *
  848.  * Purpose:
  849.  *  Informs the document that the polyline changed size.
  850.  *
  851.  * Parameters:
  852.  *  None
  853.  *
  854.  * Return Value:
  855.  *  None
  856.  */
  857.  
  858. void CPolylineAdviseSink::OnSizeChange(void)
  859.     {
  860.     LPCSchmooDoc pDoc=(LPCSchmooDoc)m_pv;
  861.     RECT         rc;
  862.     DWORD        dwStyle;
  863.  
  864.     /*
  865.      * Polyline window is informing us that it changed size in
  866.      * response to setting it's data.  Therefore we have to
  867.      * size ourselves accordingly but without moving the screen
  868.      * position of the polyline window.
  869.      */
  870.  
  871.     pDoc->m_fNoSize=TRUE;
  872.  
  873.     //Set the document window size.
  874.     GetWindowRect(pDoc->m_pPL->Window(), &rc);
  875.     InflateRect(&rc, 8, 8);
  876.  
  877.     //Adjust for a window sans menu
  878.     dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
  879.     AdjustWindowRect(&rc, dwStyle, FALSE);
  880.  
  881.     SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  882.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  883.  
  884.     if (NULL!=pDoc->m_pAdv)
  885.         pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
  886.  
  887.     pDoc->m_fNoSize=FALSE;
  888.     pDoc->FDirtySet(TRUE);
  889.  
  890.     return;
  891.     }
  892.  
  893.  
  894.  
  895.  
  896.  
  897. /*
  898.  * CPolylineAdviseSink::OnDataChange
  899.  *
  900.  * Purpose:
  901.  *  Informs the document that the polyline data changed.
  902.  *
  903.  * Parameters:
  904.  *  None
  905.  *
  906.  * Return Value:
  907.  *  None
  908.  */
  909.  
  910. void CPolylineAdviseSink::OnDataChange(void)
  911.     {
  912.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  913.  
  914.     if (NULL!=pDoc->m_pAdv)
  915.         pDoc->m_pAdv->OnDataChange(pDoc);
  916.  
  917.     pDoc->FDirtySet(TRUE);
  918.     return;
  919.     }
  920.  
  921.  
  922.  
  923.  
  924.  
  925. /*
  926.  * CPolylineAdviseSink::OnColorChange
  927.  *
  928.  * Purpose:
  929.  *  Informs the document that the polyline data changed a color.
  930.  *
  931.  * Parameters:
  932.  *  None
  933.  *
  934.  * Return Value:
  935.  *  None
  936.  */
  937.  
  938. void CPolylineAdviseSink::OnColorChange(void)
  939.     {
  940.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  941.  
  942.     pDoc->FDirtySet(TRUE);
  943.     return;
  944.     }
  945.  
  946.  
  947.  
  948.  
  949.  
  950. /*
  951.  * CPolylineAdviseSink::OnLineStyleChange
  952.  *
  953.  * Purpose:
  954.  *  Informs the document that the polyline changed its line style.
  955.  *
  956.  * Parameters:
  957.  *  None
  958.  *
  959.  * Return Value:
  960.  *  None
  961.  */
  962.  
  963. void CPolylineAdviseSink::OnLineStyleChange(void)
  964.     {
  965.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  966.  
  967.     pDoc->FDirtySet(TRUE);
  968.     return;
  969.     }
  970.